from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext_lazy as _

CHANGE_TYPES = (
    ('AD', _('Add')),
    ('CA', _('Change attr')),
    ('CP', _('Change patern')),
    ('CP', _('Change position')),
    ('DE', _('Delete')),
    ('TX', _('Text')),
)

class Page(models.Model):
    url = models.CharField(_('Url'), max_length=200, 
                           help_text=_('Enter url'))

    is_pattern = models.BooleanField(_('Is pattern'), default=False,
				    help_text=_('Is patter'))
    def __unicode__(self):
        return self.url

class Container(models.Model):
    id_html = models.CharField(_('Id HTML'), max_length=200, 
                              help_text=_('Id of the HTML container'))

    page = models.ManyToManyField(Page, verbose_name=_('Page'),
                             help_text=_('Select a page'))

    members  = models.ManyToManyField(User, verbose_name=_('Users'), through='ContainerUser')

    def __unicode__(self):
        return u"%s %s" %(self.page.all(), self.id_html)

class ContainerUser(models.Model):
    user = models.ForeignKey(User)
    container = models.ForeignKey(Container)

    def __unicode__(self):
        return u"%s %s" %(self.user, self.container)


class Change(models.Model):
    type =  models.CharField(_('change types'), max_length=2, choices=CHANGE_TYPES,
                                 help_text=_('Select a change type'))

    attr =  models.CharField(_('attrs'), max_length=100,
                                 help_text=_('Only sense in some change types'))

    value =  models.CharField(_('value'), max_length=100,
                                 help_text=_('New value'))
    container_user = models.ForeignKey(ContainerUser, verbose_name=_('ContainerUser'),
                                help_text=_('Select a Container user'))

    def __unicode__(self):
        return u"%s %s<< %s" %(self.type, self.attr, self.value)




